/*
    Copyright 2009 Spencer B. Koehler, Ph.D.

    This file is part of the Brillig Toolkit.

    The Brillig Toolkit is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Brillig Toolkit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with The Brillig Toolkit.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.brillig.util;


import java.text.BreakIterator;
import java.util.Locale;

/**
 * A naive iterator over the words in a string based on java.text.BreakIterator.
 * <p>
 * @author Spence Koehler
 */
public class WordIterator extends TextIterator {
	
	/**
	 * Construct with the string whose words are to be iterated over
	 * using the default locale.
	 */
	public WordIterator(String string) {
		super(BreakIterator.getWordInstance());
		setText(string);
	}

	/**
	 * Construct with the string whose words are to be iterated over
	 * using the given locale.
	 */
	public WordIterator(String string, Locale locale) {
		super(BreakIterator.getWordInstance(locale));
		setText(string);
	}


	/**
	 * Show segmentation of each argument.
	 */
	public static final void main(String[] args) {
		for (String arg : args) {
			System.out.println(arg + " --> ");
			for (WordIterator iter = new WordIterator(arg); iter.hasNext(); ) {
				System.out.println("\t" + iter.next());
			}
		}
	}
}
